package com.dream21th.rule.engine.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dream21th.common.ComReq;
import com.dream21th.common.ComResp;
import com.dream21th.common.dto.PageDTO;
import com.dream21th.rule.engine.biz.DroolsBaseBiz;
import com.dream21th.rule.engine.entity.DroolsBaseInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * @author dream21th
 * @Desprition TODO
 * @since 2021-07-05 14:12:32
 */
@RestController
@RequestMapping("/v1/droolsBaseInfo")
public class DroolsBaseInfoController {

    @Autowired
    private DroolsBaseBiz droolsBaseBiz;

    @PreAuthorize("hasAuthority('USER')")
    @PostMapping("/page")
    public ComResp<IPage<DroolsBaseInfo>> queryDroolsBaseInfoPage(@RequestBody ComReq<PageDTO<DroolsBaseInfo>> req) {
        return new ComResp<IPage<DroolsBaseInfo>>().data(droolsBaseBiz.droolsPage(req.getRequestData())).success();
    }

    @PostMapping("/queryOne")
    public ComResp<DroolsBaseInfo> queryDroolsBaseInfoOne(@RequestBody ComReq<DroolsBaseInfo> req) {
        return new ComResp<DroolsBaseInfo>().data(droolsBaseBiz.selectOneDrools(req.getRequestData())).success();
    }

    @PreAuthorize("hasAuthority('project:rule:add')")
    @PostMapping("/updateOrSaveOneDrools")
    public ComResp<Boolean> updateOrSaveOneDrools(@RequestBody ComReq<DroolsBaseInfo> req) {
        return new ComResp<Boolean>().data(droolsBaseBiz.updateOrSaveOneDrools(req.getRequestData())).success();
    }

    @PreAuthorize("hasAuthority('project:rule:delete')")
    @PostMapping("/deleteDrools")
    public ComResp<Boolean> delete(@RequestBody ComReq<List<Integer>> req) {
        return new ComResp<Boolean>().data(droolsBaseBiz.deleteDrools(req.getRequestData())).success();
    }
}

